const Alldata = {
	data() {
		return {
			isExist: true,
			Data: {},
			Data1: {},
			img: []
		}
	},
	methods: {
		getData() {
			axios
				.get('http://172.22.112.171:8082/api')
				.then(response => {
					var allData = response.data;
					var item;
					// 将获取数据存入本地缓存
					var tpemData = localStorage.getItem(allData);
					localStorage.setItem("allDataMsg",JSON.stringify(allData));
					var str = window.localStorage?localStorage.getItem("allDataMsg"):Cookie.read("allDataMsg");
					// 将str转化成json
					str = JSON.parse(str); 
					for (item in str) {
						var a = str[item];
						if (a.device == 'TPEM') {
							this.Data.set(a.device + '-' + a.addr, a);
						}
						if ((a.device == 'SPEM') || (a.device == 'SPEM97')) {
							this.Data1.set(a.device + '-' + a.addr, a);
						}
					}
					
					// 设置三相电表图片显示
					var length = this.Data.size;
					var value = 'images/dianbiao.png';
					this.img = new Array(length).fill(value);
					
					// 设置单相电表超过一天没更新字体位置颜色变红色
					this.Data1.forEach((v, k) => {
						var delayedTime = v.time.slice(0, 10);
						var strTimeDate = new Date(Date.parse(delayedTime.replace('/-/g', '/')))
							.getTime();
						var timeStamp = this.time - strTimeDate;
						// console.log(timeStamp)
						if (timeStamp >= 86400000) {
							var id = v.device + '-' + v.addr;
							var element = document.getElementById(id);
							if(element != null){
								element.className = 'red';
							}
						}
					});
					var index = -1;
					// 设置三相电表超过一天没更新字体位置颜色变红色
					this.Data.forEach((v, k) => {
						index += 1;
						var delayedTime = v.time.slice(0, 10);
						var strTimeDate = new Date(Date.parse(delayedTime.replace('/-/g', '/')))
							.getTime();
						var timeStamp = this.time - strTimeDate;
						if (timeStamp >= 86400000) {
							var id = v.device + '-' + v.addr;
							var element = document.getElementById(id);
							if(element != null){
								element.className = 'red';
							}
							this.img[index] = 'images/dianbiao1.png';
						}
					});
				})
				.catch(function(error) { // 请求失败处理
					console.log(error);
				});
		},
		//获取时间戳
		time() {
			this.time = new Date().getTime();
		}
	},
	mounted() {
		var Data = new Map();
		var Data1 = new Map();
		this.Data = Data;
		this.Data1 = Data1;
		this.getData();
		var that = this;
		setInterval(function() {
			that.getData();
		}, 1000);
		this.time();
	}
}